/*
package com.doit.day02


import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.serializer.SerializerFeature

import java.sql.{Connection, DriverManager, PreparedStatement, ResultSet}
import java.util
import scala.collection.JavaConverters
import scala.collection.mutable.ListBuffer
import scala.io.Source

object FileIterator {
  def main(args: Array[String]): Unit = {
   /* val iterator: ScalaFileIterator = new ScalaFileIterator
    while (iterator.hasNext){
      println(iterator.next())
    }

    val iterator1: ScalaMysqlIterator = new ScalaMysqlIterator
    while (iterator1.hasNext){
      println(iterator1.next())
    }*/

  }
}


class ScalaFileIterator extends Iterator[Hero] {
  private val lines: Iterator[String] = Source.fromFile("data/Hero.txt").getLines()
  override def hasNext: Boolean = lines.hasNext
  override def next(): Hero = {
    val line: String = lines.next()
    val arr: Array[String] = line.split(",")
    val arr1: Array[String] = arr(1).split("_")
    val arr2: Array[String] = arr1(1).split("::")
    new Hero(arr(0).toInt, arr1(0), arr2(0).toInt, arr2(1).toInt)
  }
}

class ScalaMysqlIterator extends Iterator[String] {
  private val conn: Connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456")
  private val pps: PreparedStatement = conn.prepareStatement("select * from user_info")
  private val set: ResultSet = pps.executeQuery()

  override def hasNext: Boolean = set.next()

  override def next(): String = {
    val id: Int = set.getInt("id")
    val name: String = set.getString("name")
    val age: Int = set.getInt("age")
    val gender: String = set.getString("gender")
    val user_info: UserInfo = new UserInfo(id, name, age, gender)
    //在scala中用fastJson去解析对象变成字符串的时候，可能会遇到问题==》方法重载的问题，解决方法如下，自己吧第二个参数穿进去就可以了
    JSON.toJSONString(user_info,SerializerFeature.PrettyFormat)
  }
}*/
